<?php
/**
 * SemesterViewSectionTimetable Model
 *
 * Utilizes the Data Mapper pattern to persist data. Represents a single
 * semester_view_section_timetable entry
 *
 * @version $Id: SemesterViewSectionTimetable.php 73 2010-04-25 00:30:44Z yingkuang.chen@gmail.com $
 * @license New BSD License
 * @uses Semester_Model_SemesterViewSectionTimetableMapper
 * @package semester
 * @subpackage Model
 */
class Semester_Model_SemesterViewSectionTimetable extends Semester_Model_Doctrine_BaseSemesterViewSectionTimetable
{


    /**
     * 取得學期排課資料
     * @param unknown_type $year
     * @param unknown_type $semester
     * @param unknown_type $grade
     * @param unknown_type $class_sn
     * @return unknown_type
     */
     public function getSemesterData($year,$semester,$grade,$class_sn)
     {

        $q = $this->getTable()->createQuery('a')
        ->where('year=?',$year)
        ->andwhere('semester=?',$semester)
        ->andwhere('grade=?',$grade)
        ->andwhere('class_sn=?',$class_sn);

        $res =  $q->fetchArray();
        $arr = array();
        foreach($res as $row) {
            $arr[$row['sn']][$row['day']] = $row;
        }

        return $arr;
     }

     /**
      * 學期班級排課統計
      * @param $year
      * @param $semester
      * @param $grade
      * @param $class_sn
      * @return unknown_type
      */
     public function  getSemesterSignData($year,$semester,$grade,$classSn)
     {

        $q = $this->getTable()->createQuery('a')
        ->select('COUNT(*) AS cc, subject_sn, teacher_sn, time_sn')
        ->where('year=?',$year)
        ->where('semester=?',$semester)
        ->where('grade=?',$grade)
        ->where('class_sn=?',$classSn)
        ->groupBy('subject_sn , teacher_sn');

        $res = $q->fetchArray();
        $arr = array();
        foreach($res as $row){
            $arr[$row['subject_sn']][$row['teacher_sn']]    = $row;
        }

        return $arr;
     }
}
